package com.ruitu.health_1.ui;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.ruitu.arad.base.base_list.BaseRefreshActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.support.widget.progress.ProgressLayout;
import com.ruitu.health_1.R;
import com.ruitu.health_1.dao.bean.Collect;
import com.ruitu.health_1.mvp.model.UserInfoModel;
import com.ruitu.health_1.mvp.presenter.UserInfoPresent;
import com.ruitu.router_module.AppHolder;

import java.util.List;

public class CollectActivity extends BaseRefreshActivity<UserInfoPresent.CollectListP, UserInfoModel.CollectListM> {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_collect;
    }

    @Override
    protected void initViews() {
        super.initViews();
        getCollect();
    }

    private DataAdapter adapter;

    @Override
    protected RecyclerView.Adapter initAdapter() {
        adapter = new DataAdapter(this);
        return adapter;
    }

    @Override
    protected LRecyclerView findRecyclerView() {
        return findViewById(R.id.l_recyclerview);
    }

    @Override
    protected void reqFirst() {
        size = 10;
        getCollect();
    }

    @Override
    protected void reqMore() {
        size = size + 10;
        getCollect();
    }

    private int size = 10;

    private void getCollect() {
        p.collectList(1, size, AppHolder.instance().getUser().getId());
    }

    public void setData(List<Collect> collectList) {
        adapter.setDataList(collectList);
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    class DataAdapter extends ListBaseAdapter<Collect> {

        public DataAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_commodity;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            ImageView iv_pic = holder.getView(R.id.icon);
            TextView tv_pro_name = holder.getView(R.id.tv_pro_name);
            TextView tv_price = holder.getView(R.id.tv_price);
            Collect collect = mDataList.get(position);
            tv_pro_name.setText(collect.getContent().getName());
            tv_price.setText(collect.getContent().getPrice());
            Glide.with(mContext).load(collect.getContent().getPic()).into(iv_pic);
        }
    }
}
